#!/bin/bash

# Compile MBR, VBR and kernel
	echo " # Compile MBR, VBR and kernel..."
	nasm mbr.asm -o mbr.bin
	nasm vbr.asm -o vbr.bin
	nasm kernel.asm -o kernel.bin

# Compile core
	echo " # Compiling core..."
	nasm ./core/core.asm -o ./fsgen/rootfs/core

# Recompile FSGEN
	echo " # Recompiling FSGEN"
	fsgen/build-fsgen

# Generate file system
	echo " # Generating file system..."
	./fsgen/fsgen ./fsgen/rootfs ./rootfs.hdd 256 2>&1 > fsgen.log

# Generate final hard disk image
	echo " # Generating final hard disk image..."
	cat mbr.bin vbr.bin kernel.bin rootfs.hdd > image.hdd
#	cat mbr.bin vbr.bin 111 rootfs.hdd > hdd

# Clean up
	echo " # Cleaning up..."
	rm -rf *.bin

# Start QEMU or BOCHS
	if [ "$1" = "bochs" ]; then
		echo " # All done! Starting Bochs..."
		bochs -f aos.bochs-conf -q -log bochs.log
	else
		echo " # All done! Starting QEmu..."
		qemu-system-x86_64 -hda image.hdd -monitor stdio -D qemu.log
	fi
#	qemu-system-x86_64 -hda hdd
